﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace DotNetStar.TheKing.Domain.Migrations
{
    public partial class v1_Initialization : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ContentComments",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    AuthorId = table.Column<long>(nullable: false),
                    AuthorUserName = table.Column<string>(maxLength: 30, nullable: false),
                    Body = table.Column<string>(nullable: false),
                    ContentId = table.Column<long>(nullable: false),
                    PostedTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ContentComments", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Contents",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    AuthorId = table.Column<long>(nullable: false),
                    AuthorUserName = table.Column<string>(maxLength: 30, nullable: false),
                    Body = table.Column<string>(nullable: false),
                    Channel = table.Column<int>(nullable: false),
                    PostedTime = table.Column<DateTime>(nullable: false),
                    Status = table.Column<int>(nullable: false),
                    Subject = table.Column<string>(maxLength: 60, nullable: false),
                    VisitNum = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Contents", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PointsStrategies",
                columns: table => new
                {
                    Id = table.Column<string>(maxLength: 20, nullable: false),
                    ExpPoints = table.Column<int>(nullable: false),
                    Name = table.Column<string>(maxLength: 30, nullable: false),
                    TradingPoints = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PointsStrategies", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "UserPointList",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreatedTime = table.Column<DateTime>(nullable: false),
                    Exp = table.Column<int>(nullable: false),
                    PointStrategyId = table.Column<string>(maxLength: 20, nullable: false),
                    Remark = table.Column<string>(maxLength: 100, nullable: true),
                    TradingPoints = table.Column<int>(nullable: false),
                    UserId = table.Column<long>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserPointList", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Users",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    AvatarUrl = table.Column<string>(maxLength: 150, nullable: true),
                    Email = table.Column<string>(maxLength: 300, nullable: true),
                    EmailConfirmed = table.Column<bool>(nullable: false),
                    ExpMaxPoints = table.Column<long>(nullable: false),
                    ExpPoints = table.Column<long>(nullable: false),
                    LastLoginTime = table.Column<DateTime>(nullable: false),
                    Level = table.Column<int>(nullable: false),
                    Mobile = table.Column<string>(maxLength: 16, nullable: true),
                    MobileConfirmed = table.Column<bool>(nullable: false),
                    Password = table.Column<string>(maxLength: 128, nullable: false),
                    PasswordSalt = table.Column<string>(maxLength: 128, nullable: false),
                    SecurityToken = table.Column<string>(nullable: true),
                    Status = table.Column<int>(nullable: false),
                    TradingPoints = table.Column<int>(nullable: false),
                    UserName = table.Column<string>(maxLength: 30, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Users", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Users_Email",
                table: "Users",
                column: "Email",
                unique: true,
                filter: "[Email] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Users_Mobile",
                table: "Users",
                column: "Mobile",
                unique: true,
                filter: "[Mobile] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Users_UserName",
                table: "Users",
                column: "UserName",
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "ContentComments");

            migrationBuilder.DropTable(
                name: "Contents");

            migrationBuilder.DropTable(
                name: "PointsStrategies");

            migrationBuilder.DropTable(
                name: "UserPointList");

            migrationBuilder.DropTable(
                name: "Users");
        }
    }
}
